package service

import (
	"context"
	balanceClient "zxs-micro-2/zxs-micro-balance-client/client"
	balanceConfig "zxs-micro-2/zxs-micro-balance-client/config"
	"zxs-micro-2/zxs-micro-proto/balancepb/balance"
	"zxs-micro-2/zxs-micro-proto/serverfindpb/serverfind"
	serverfindClient "zxs-micro-2/zxs-micro-serverfind-client/client"
	serverfindConfig "zxs-micro-2/zxs-micro-serverfind-client/config"
)

type WangGuanService struct {
	sfClient serverfind.ServerFindServiceClient
	lbClient balance.BalanceServiceClient
}

var s *WangGuanService

func init() {
	s = new(WangGuanService)
}

//网关负责接收客户端发送的消息(http)，然后转发至其他服务(grpc)
func InitWangGuanService() {
	ctx := context.Background()
	serverfindConfig.Cfg.ServerType = "wangguan"
	serverfindConfig.Cfg.ClientPort = "-1"
	selfId, err := serverfindClient.InitServerFindClient()
	if err != nil {
		panic(err)
	}
	s.sfClient = serverfindClient.GetClient()
	balanceConfig.Cfg.SelfIpAddr = serverfindClient.GetSelfIpAddr(ctx)
	balanceConfig.Cfg.ServiceType = "wangguan"
	balanceClient.InitBalanceClient(selfId)
	s.lbClient = balanceClient.GetBalanceClient()
	//todo 监听指定端口，根据协议，输入数据，进行转发
	//todo 还需要加入流量限制option和灰度option。。。
	ServerHTTP()
}
